<?php
class Servicemanager_Model_Pagedecision implements Servicemanager_Model_Mainable{
    
    private $core_controller_csrftoken;
    private $get_access_levels;
    private $get_statuses_name;
    private $get_all_images;
    private $get_subcategory_list;
    private $action_handler;
    
    public function main(array $variables = null) {
        switch($variables['get']['page']){
            case 'dodaj-usluge':
                return $this->add_service($variables);
                break;
            case 'wstaw-usluge':
                return $this->insert_service($variables);
                break;
            case 'edytuj-usluge':
                return $this->edit_service($variables);
                break;
            case 'aktualizuj-usluge':
                return $this->update_service($variables);
                break;
            case 'usun-usluge':
                return $this->deleta_service($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    private function deleta_service(array $variables = null){
        $this->action_handler = new Servicemanager_Model_Deletecurrentservice;
        return $this->action_handler->main($variables);
    }
    
    private function update_service(array $variables = null){
        $this->action_handler = new Servicemanager_Model_Editcurrentservice;
        return $this->action_handler->main($variables);
    }
    
    private function edit_service(array $variables = null){
        $page = $this->get_other_data($variables);
        $this->action_handler = new Servicemanager_Data_Getcurrentservice;
        $page['content'] = $this->action_handler->main($variables);
        return $page;
    }
    
    private function insert_service(array $variables = null){
        $this->action_handler = new Servicemanager_Model_Insertnewservice;
        return $this->action_handler->main($variables);
    }
    
    private function add_service(array $variables = null){
        $page = $this->get_other_data($variables);
        return $page;
    }
    
    private function get_other_data(array $variables = null){
        $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
        $this->get_access_levels = new Privileges_Data_Getpriviligeslist;
        $this->get_all_images = new Imageupload_Data_Getallimages;
        $this->get_statuses_name = new Accountsstatus_Data_Getaccountsstatus;
        $this->get_subcategory_list = new Subcategorymanager_Data_Getallsubcategories;
        
        $page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
        $page['access_level'] = $this->get_access_levels->main($variables);
        $page['image'] = $this->get_all_images->main($variables);
        $page['status'] = $this->get_statuses_name->main($variables);
        $page['subcategory'] = $this->get_subcategory_list->main($variables);
        
        $page['template'] = WEB_ROOT_FOLDER."servicemanager/views/addservice.php";
        
        return $page;
    }
    
    private function default_action(array $variables = null){
        unset($variables['get']);
        $this->action_handler = new Servicemanager_Model_Servicemanager;
        return $this->action_handler->main($variables);
    }

}
